package com.eco.fanliapp.controller.app;

import com.eco.fanliapp.common.base.AuthController;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.entity.AppNewsLog;
import com.eco.fanliapp.entity.AppUser;
import com.eco.fanliapp.service.IAppNewsLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
/**
 * @ProjectName: fanliapp
 * @Package: com.eco.fanliapp.controller.app
 * @ClassName: AppMessageController
 * @Author: xiaoxx
 * @Description: 消息
 * @Date: 2019/11/28 15:13
 * @Version: 4.2.2
 */
@Controller
@RequestMapping("/app/message/user")
public class AppMessageController extends AuthController {

    @Autowired
    private IAppNewsLogService iAppNewsLogService;

    //消息(列表)--新
    @GetMapping("/list")
    @ResponseBody
    public ServerResponse<List<AppNewsLog>> getMessageList(Integer msgType, Integer pageNum, Integer pageSize){
        AppUser u = getAppUser();
        if(null == u) {
            return ServerResponse.createByErrorCodeMessage(301,"Token不正确");
        }
        return iAppNewsLogService.getMessageList(u.getUserId(),pageNum,pageSize,msgType);
    }

    //已读所有消息
    @GetMapping("/AllMessageToRead")
    @ResponseBody
    public ServerResponse<List<AppNewsLog>> AllMessageToRead(String msgType){
        AppUser u = getAppUser();
        if(null == u) {
            return ServerResponse.createByErrorCodeMessage(301,"Token不正确");
        }
        return iAppNewsLogService.AllMessageToRead(u.getUserId(),msgType);
    }

    //获取未读消息数
    @GetMapping("/getNoReadMessage")
    @ResponseBody
    public ServerResponse getNoReadMessage(String msgType){
        AppUser u = getAppUser();
        if(null == u) {
            return ServerResponse.createByErrorCodeMessage(301,"Token不正确");
        }
        return iAppNewsLogService.getNoReadMessage(u.getUserId(),msgType);
    }

    //根据id已读部分消息
    @GetMapping("/MessageToRead")
    @ResponseBody
    public ServerResponse MessageToRead(String ids){
        AppUser u = getAppUser();
        if(null == u) {
            return ServerResponse.createByErrorCodeMessage(301,"Token不正确");
        }
        return iAppNewsLogService.MessageToRead(u.getUserId(),ids);
    }
}
